import 'dart:convert' show json;

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}

class UserInfoEdit {
  UserInfoEdit({
    this.company,
    this.nickname,
    this.portrait,
    this.sexual,
    this.sign,
    this.city,
    this.position,
    this.email,
  });

  factory UserInfoEdit.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : UserInfoEdit(
    company: asT<String>(jsonRes['company']),
    nickname: asT<String>(jsonRes['nickname']),
    portrait: asT<String>(jsonRes['portrait']),
    sexual: asT<String>(jsonRes['sexual']),
    sign: asT<String>(jsonRes['sign']),
    city: asT<String>(jsonRes['city']),
    position: asT<String>(jsonRes['position']),
    email: asT<String>(jsonRes['email']),
  );

  String company;
  String nickname;
  String portrait;
  String sexual;
  String sign;
  String city;
  String position;
  String email;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'company': company,
    'nickname': nickname,
    'portrait': portrait,
    'sexual': sexual,
    'sign': sign,
    'city': city,
    'position': position,
    'email': email,
  };

  @override
  String toString() {
    return json.encode(this);
  }
}